package com.broada.apm.servlet;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;

import com.broada.apm.utils.ConfigureProperties;

@WebServlet("/resource/*")
public class ImageServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("image/png");
		//80/Logo.png
		String contextPath = this.getServletContext().getContextPath();
		String requestURI = req.getRequestURI();
				requestURI = requestURI.substring((contextPath + "/resource/" ).length());
		//"../conf/l7Module/"
		String moduleDir = ConfigureProperties.getString("apm.web.17Module.logo","../conf/l7Module");
		FileInputStream input = new FileInputStream(new File(moduleDir,requestURI).getAbsoluteFile());
		ServletOutputStream writer = resp.getOutputStream();
		IOUtils.copy(input, writer);
		input.close();
		resp.flushBuffer();
	}
}
